var $,
    table,
    layer;

layui.use(['jquery', 'table', 'layer'], function () {
    $ = layui.jquery,
        table = layui.table,
        layer = layui.layer;
});


getTable();
function getTable() {
    layui.use(['jquery', 'table', 'layer'], function () {
        $ = layui.jquery,
            table = layui.table,
            layer = layui.layer;

        table.render({
            elem: '#demo'
            ,url: '/Conversation/getTable' //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                {type: 'checkbox'}
                ,{title: '序号', align: 'center', templet: function (data) {
                        return data.LAY_INDEX;
                    }}
                ,{field: 'fromname', title: '发送人', align: 'center'}
                ,{field: 'toname', title: '接收人', align: 'center'}
                ,{field: 'content', title: '消息内容', align: 'center'}
                ,{field: 'sendTime', title: '发送时间', align: 'center'}
                ,{field: 'state', title: '类型', align: 'center', templet: function (data) {
                        if (data.state == 1){
                            return '提问';
                        }else{
                            return '解答';
                        }
                    }}
                ,{field: '', title: '操作', align: 'center', templet: function (data) {
                        return '<a style="color: #0DAB9D;" href="javascript:getRecord(\''+data.id+'\')">查看记录</a> &nbsp; ' +
                            '<a style="color: #0DAB9D;" href="javascript:deleteRecord(\''+data.id+'\')">删除记录</a>'
                    }}
            ]]
        });
    });
}


//查看记录
function getRecord(id){
    layer.open({
        type: 2,
        title: '客服详情',
        area:['1500px', '780px'],
        maxmin: true,
        offset: 't',
        resize: false,
        content: '/authority/layer-customService-selectRecord.html',
    })
}

//删除记录
function deleteRecord(id){
    $.ajax({
        url: '/Conversation/deleteRecord',
        data: {'id': id},
        dataType: 'json',
        success: function (item) {
            if (item.data){
                layer.msg('删除成功');
                getTable();
            } else {
                layer.msg('删除失败');
            }
        }
    })
}
